﻿
@using Newtouch.Infrastructure
@{
    ViewBag.Title = "发票获取与验收";
    Layout = "~/Views/Shared/_Index.cshtml";

}


<style>
    /*.inline {
        width: 80%;
        display: inline;
    }

    .PriceInline {
        width: 70%;
        display: inline;
    }

    #dv-detail table th {
        border: solid 1px #ddd;
        padding: 0;
        vertical-align: middle;
    }

    #dv-detail .ui-jqgrid-labels, #dv-detail .jqgrow .ui-row-ltr {
        height: 30px;
        vertical-align: middle;
    }


    #dv-detail table td {
        border: solid 1px #ddd;
        padding: 0;
        vertical-align: middle;
    }

    #dv-detail input[role=textbox] {
        padding: 2px 2px;
    }

    #gridList .ckbox label {
        margin-top: 24px;
    }*/
</style>
<form id="form1">
    <div class="panel panel-default" style="margin-bottom:10px;">
        <div class="panel-heading">库存信息</div>
        <table class="form">
            <tr>
                <th class="formTitle ">关键字：</th>
                <td class="formValue">
                    <input type="text" id="keyword" name="keyword" class="form-control" placeholder="药品名称/代码" autocomplete="off" style="width:60%" />
                </td>

                <td class="formValue" style="width:115px;">
                    <div class="ckbox ckmargin">
                        <input id="chk_NoShow0KC" type="checkbox" /><label for="chk_NoShow0KC">不显示零库存</label>
                    </div>
                </td>

                <th class="formTitle">
                    <input type="button" id="btn_search" class="btn btn-md btn-primary" value="查询" />
                </th>
                <td></td>
            </tr>
        </table>
    </div>
    <div id="dv-detail">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>

</form>

<script type="text/javascript">

    $(function () {
        InitFloat();

        gridList();
    });


    //初始化浮层
    function InitFloat() {

    }

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/StorageManage/DrugStockSearch/GetStockExpiredSearchByPage",
            height: $(window).height() - 200,
            postData: {
                keyword: $("#keyword").val(), show0kc : $("#chk_NoShow0KC").is(":checked") ? "0" : "1"},
            editurl: "clientArray",  //行编辑不向服务器提交数据
            colModel: [

                //{ label: 'Id', name: 'Id', hidden: true },
                { label: '药品代码', name: 'ypdm', width: 80, align: 'left' },
                { label: '药品名称', name: 'ypmc', width: 180, align: 'left' },
                { label: '药品规格', name: 'gg', width: 120, align: 'left' },
                { label: '单位', name: 'dw', width: 60, align: 'center' },
                { label: '药品产地', name: 'ycmc', width: 100, align: 'left' },
                { label: '库存数量', name: 'slStr', width: 60, align: 'left' },
                { label: '零售价格', name: 'lsjdjdw', width: 80, align: 'left' },
                { label: '有效期', name: 'yxq', width: 80, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' } },
                { label: '批次', name: 'pc', width: 120, align: 'left' },
                { label: '批号', name: 'ph', width: 60, align: 'left' },
                { label: '库存Id', name: 'kcId', width: 100, align: 'left', hidden: true },
                { label: '创建时间', name: 'createtime', width: 100, align: 'left', hidden: true },
                { label: '操作', name: 'action', align: 'center', width: 100, formatter: function (val) { return "<input class='btn btn-default btn-md btn_add' type='button' value='修改有效期' onclick='updateRow($(this).parent().parent().attr(\"id\"))'/>"; } },
            ],

            multiselect: false,

            pager: "#gridPager",
            sortname: 'ypdm,yxq ,createtime asc',
            viewrecords: true,
            ondblClickRow: function (rowid, iRow, iCol, e) {
                //btn_selectrow(rowid);
            },
            gridComplete: function () {
                EnableInlineEditBox();
            }
        });
    }

    //查询
    $('#btn_search').click(function () {

        $("#gridList").jqGrid('setGridParam', {
            url: '/StorageManage/DrugStockSearch/GetStockExpiredSearchByPage',
            postData: { keyword: $("#keyword").val(), show0kc: $("#chk_NoShow0KC").is(":checked") ? "0" : "1" }, page: 1
        }).trigger('reloadGrid');

        gridList();
    });


    function updateRow(rowid) {
        var rowData = $("#gridList").jqGrid('getRowData', rowid);
        if (rowData == null) {
            $.modalMsg("未找到当前行", 'error');
        }
        $.modalOpen({
            id: "ExpiredDateForm",
            title: "修改有效期",
            url: "/StorageManage/DrugStockSearch/ExpiredDateForm?kcId=" + rowData.kcId + "&yxq=" + rowData.yxq,
            width: "500px",
            height: "400px",
            callBack: function (iframeId) {
                var obj = top.frames[iframeId].SubmitForm();

                $.submitForm({
                    url: "/StorageManage/DrugStockSearch/UpdateExpired",
                    param: { kcId: obj.kcId, yxq: obj.yxq },
                    success: function () {
                        $.modalMsg('修改成功', 'success');
                        $("#btn_search").trigger('click');
                        $.modalClose();
                        callback();
                    }
                });

                $.modalClose("ExpiredDateForm");

            }
        });
    }


    function EnableInlineEditBox() {
        var ids = $("#gridList").getDataIDs();
        $.each(ids, function () {
            var rowid = String(this);
            //打开编辑模式
            $("#gridList").jqGrid('editRow', rowid, false, initInlineFunc);
        })
    }

    function initInlineFunc(rowid) {
        //$("#" + rowid + "_ypdm").css('background-color', '#f6f7fb').attr('readonly', 'true');
        //$("#" + rowid + "_ypmc").css('background-color', '#f6f7fb').attr('readonly', 'true');
        $("#" + rowid + "_gg").css('background-color', '#f6f7fb').attr('readonly', 'true');
        $("#" + rowid + "_dw").css('background-color', '#f6f7fb').attr('readonly', 'true');
        $("#" + rowid + "_ycmc").css('background-color', '#f6f7fb').attr('readonly', 'true');
        $("#" + rowid + "_slStr").css('background-color', '#f6f7fb').attr('readonly', 'true');
        $("#" + rowid + "_lsjdjdw").css('background-color', '#f6f7fb').attr('readonly', 'true');
        $("#" + rowid + "_pc").css('background-color', '#f6f7fb').attr('readonly', 'true');
        $("#" + rowid + "_ph").css('background-color', '#f6f7fb').attr('readonly', 'true');
    }


</script>


